package com.study.mike.spring.sample.cr;

import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class CirculationRefXmlTest {

    private ApplicationContext context;

    @Before
    public void prepare() {
        context = new ClassPathXmlApplicationContext("com/study/mike/spring/sample/cr/application.xml");
    }

    @Test
    public void constructorCirculationRefTest() {
        //spring无法解决构造方法的循环依赖, 单例原型都不行
        ConstructorCirculationRefA ccra = context.getBean(ConstructorCirculationRefA.class);
        ConstructorCirculationRefB ccrb = context.getBean(ConstructorCirculationRefB.class);
    }

    @Test
    public void propertyCirculationRefTest() {
        //如果至少有一方是单例, Spring可以解决循环依赖; 如果所有bean都是原型, 则无法解决
        PropertyCirculationRefA ccra = context.getBean(PropertyCirculationRefA.class);
        PropertyCirculationRefB ccrb = context.getBean(PropertyCirculationRefB.class);
        PropertyCirculationRefC ccrc = context.getBean(PropertyCirculationRefC.class);
    }

}
